package com.itheima.tanhua.service;


import com.itheima.tanhua.pojo.mongo.Friend;
import com.itheima.tanhua.pojo.mongo.MovementTimeLine;
import com.itheima.tanhua.api.mongodb.TimeLineApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TimeLineService {

    @DubboReference
    private TimeLineApi timeLineService;
    @Async   //异步的标志
    public void saveTimeLine(Long uid, ObjectId mid) {
        /*
        根据uid 查询   friendId
        通过friendId  添加时间线 异步添加
         */
        //获取朋友的集合列表
        List<Friend> friendList = timeLineService.findFriends(uid);
        for (Friend friend : friendList) {
            //添加时间线  没有friendId对应一个时间线
            MovementTimeLine movementTimeLine = new MovementTimeLine();
            movementTimeLine.setMovementId(mid);
            movementTimeLine.setCreated(friend.getCreated());
            movementTimeLine.setUserId(friend.getUserId());
            movementTimeLine.setFriendId(friend.getFriendId());
            timeLineService.saveMovementTimeLine(movementTimeLine);
        }

    }

}
